package com.example.siyun.util;

import lombok.extern.slf4j.Slf4j;
import org.csource.fastdfs.ClientGlobal;
import org.csource.fastdfs.TrackerClient;
import org.csource.fastdfs.TrackerServer;

import java.io.IOException;
/**
 * @Auther: 全
 * @Date: 2022/10/11 09:34
 * @Description:上传文件的工具类
 */
@Slf4j
public class FastDFSClienta {
    //返回带端口号的图片服务器ip地址
    public static String getTrackerUrl() throws IOException {
        log.info("获取到了上传的图片的返回路径"+"http://"+getTrackerServer().getInetSocketAddress().getHostString()+":"+ ClientGlobal.getG_tracker_http_port()+"/");
        return "http://"+getTrackerServer().getInetSocketAddress().getHostString()+":"+ ClientGlobal.getG_tracker_http_port()+"/";
    }

    //返回不带端口号的图片服务其ip连接地址
    public static String getUrl() throws IOException {
        log.info("图片服务其ip连接地址"+"http://"+getTrackerServer().getInetSocketAddress().getHostString()+"/");
        return "http://"+getTrackerServer().getInetSocketAddress().getHostString()+"/";
    }
    private static TrackerServer getTrackerServer() throws IOException {
        TrackerClient trackerClient = new TrackerClient();
        TrackerServer trackerServer = trackerClient.getConnection();
        return  trackerServer;
    }

}
